package com.thb.pay.channel.accountpay;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.thb.pay.channel.AbsPaymentService;
import com.thb.pay.comm.dto.ExtraInfoDTO;
import com.thb.pay.comm.utils.ChannelConstants;
import com.thb.pay.core.exception.RRException;
import com.thb.pay.exception.PaymentGatewayEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @类名称 CurrentpayPayService
 * @类描述 <pre>系统账户平台支付接口</pre>
 * @作者 lucky
 * @创建时间 2019/10/25
 * @版本 v1.01
 */
@Component
public class AccountPaymentService extends AbsPaymentService {

    @Override
    public String channel() {
        return ChannelConstants.CHANNEL_ACCOUNT;
    }

    @Override
    public ExtraInfoDTO checkExtra(String extra) {
        if (StringUtils.isBlank(extra)) {
            throw RRException.build(PaymentGatewayEnum.EXTRA_NOT_EMPTY_ERROR, "extra");
        }
        JSONObject extraJson = JSON.parseObject(extra);
        if (!extraJson.containsKey("userId") || StringUtils.isBlank(extraJson.getString("userId"))) {
            throw RRException.build(PaymentGatewayEnum.EXTRA_NOT_EMPTY_ERROR, "extra.userId");
        }
        return ExtraInfoDTO.buildUserInfo(extraJson.getString("userId"));
    }
}
